<template>
    <el-dialog :visible.sync="show" title="审核培养方案" width="50%" :close-on-click-modal="false"
            :close-on-press-escape="false">
        <div class="edu-auto-row">
            <div class="edu-auto-col">
                <div class="edu-auto-label">方案名称：</div>
                <div :title="schemeInfo.name" class="edu-auto-content">{{ schemeInfo.name }}</div>
            </div>
            <div class="edu-auto-col">
                <div class="edu-auto-label">年级：</div>
                <div class="edu-auto-content">{{ schemeInfo.grade }}</div>
            </div>
            <div class="edu-auto-col">
                <div class="edu-auto-label">学院：</div>
                <div
                    :title="schemeInfo.facultyI18n"
                    class="edu-auto-content"
                >{{ schemeInfo.facultyI18n }}</div>
            </div>
            <template v-if="schemeInfo.projId == 1">
                <div class="edu-auto-col">
                    <div class="edu-auto-label">类别:</div>
                    <div
                        :title="schemeInfo.professionCateGory == '1'? '专业大类': '专业'"
                        class="edu-auto-content"
                    >{{ schemeInfo.professionCateGory == "1"? "专业大类": "专业" }}</div>
                </div>
                <div class="edu-auto-col">
                    <div class="edu-auto-label">校内专业：</div>
                    <div
                        :title="schemeInfo.campusProfessionName"
                        class="edu-auto-content"
                    >{{ schemeInfo.campusProfessionName }}</div>
                </div>
            </template>
            <div class="edu-auto-col" v-else>
                <div class="edu-auto-label">学科专业：</div>
                <div :title="schemeInfo.majorI18n" class="edu-auto-content">{{ schemeInfo.majorI18n }}</div>
            </div>

            <div class="edu-auto-col">
                <div class="edu-auto-label">培养层次：</div>
                <div
                    :title="schemeInfo.trainingLevelI18n"
                    class="edu-auto-content"
                >{{ schemeInfo.trainingLevelI18n }}</div>
            </div>
            <template v-if="schemeInfo.projId != 1">
                <div class="edu-auto-col">
                    <div class="edu-auto-label">培养类别：</div>
                    <div
                        :title="schemeInfo.trainingCategoryI18n"
                        class="edu-auto-content"
                    >{{ schemeInfo.trainingCategoryI18n }}</div>
                </div>
                <div class="edu-auto-col">
                    <div class="edu-auto-label">学位类型：</div>
                    <div
                        :title="schemeInfo.degreeTypeI18n"
                        class="edu-auto-content"
                    >{{ schemeInfo.degreeTypeI18n }}</div>
                </div>
                <div class="edu-auto-col">
                    <div class="edu-auto-label">学位类别：</div>
                    <div
                        :title="schemeInfo.degreeCategoryI18n"
                        class="edu-auto-content"
                    >{{ schemeInfo.degreeCategoryI18n }}</div>
                </div>
                <div class="edu-auto-col">
                    <div class="edu-auto-label">学习形式：</div>
                    <div
                        :title="schemeInfo.formLearningI18n"
                        class="edu-auto-content"
                    >{{ schemeInfo.formLearningI18n }}</div>
                </div>
                <!-- <div class="edu-auto-col">
                    <div class="edu-auto-label">专项计划：</div>
                    <div
                        :title="schemeInfo.spcialPlanI18n"
                        class="edu-auto-content"
                    >{{ schemeInfo.spcialPlanI18n }}</div>
                </div>
                <div class="edu-auto-col">
                    <div class="edu-auto-label">国际学生：</div>
                    <div class="edu-auto-content">
                        <span v-if="schemeInfo.studentAbroad == 0">是</span>
                        <span v-if="schemeInfo.studentAbroad == 1">否</span>
                    </div>
                </div>
                <div class="edu-auto-col">
                    <div class="edu-auto-label">学制：</div>
                    <div class="edu-auto-content">{{ schemeInfo.lengthSchooling }}</div>
                </div>
                <div class="edu-auto-col">
                    <div class="edu-auto-label">学习年限：</div>
                    <div class="edu-auto-content">{{ schemeInfo.maxLengthSchooling }}</div>
                </div> -->
            </template>
        </div>
        <div class="hr"></div>
        <!-- <div class="edu-auto-row">
            <div class="edu-auto-col full-col">
                <div class="edu-auto-label require">材料说明：</div>
                <div class="edu-auto-content">
                    <el-input
                        :rows="3"
                        v-model="examineInfo.editExplain"
                        type="textarea"
                        placeholder="请输入内容"
                        style="width: 100%;min-height: 80px;"
                    />
                </div>
            </div>
        </div> -->
        <div class="edu-auto-row">
            <div class="edu-auto-col">
                <div class="edu-auto-label" style="width:170px">签字版培养方案扫描件：</div>
                <div class="edu-auto-content">
                    <el-upload
                        :headers="{'X-Token': $store.state.session.sessionid}"
                        :data="{bucketname: 'face', folderpath: 'file'}"
                        :on-preview="handleAvatarPreview"
                        :on-remove="handleAvatarRemove"
                        :on-success="handleUploadSuccess"
                        :file-list="examineFileList"
                        :before-upload="beforeAvatarUpload"
                        class="upload-demo"
                        action="/api/commonservice/obsfile/uploadfile"
                        multiple
                    >
                        <el-button size="small" type="primary">点击上传</el-button>
                    </el-upload>
                </div>
            </div>
        </div>
        <span slot="footer" class="dialog-footer">
            <el-button @click="closeDialog">取 消</el-button>
            <el-button type="primary" @click="submitExamine">确 定</el-button>
        </span>
    </el-dialog>
</template>
<script>
import * as API from "common/src/api/culture/cultruescheme";
import Bus from "common/src/utils/bus";
export default {
    props: {
        show: {
            default: false,
            type: Boolean
        },
        id: {
            default: null,
            type: String
        },
        type: {
            default: null,
            type: String
        },
        randomId: {
            default: 0,
            type: Number
        }
    },
    data() {
        return {
            componentShow: this.show,
            schemeInfo: "",
            examineFileList: [],
            examineInfo: {
                type: this.type,
                id: "",
                //editExplain: "",
                evidenceList: []
            }
        };
    },
    watch: {
        show(val) {
            this.componentShow = val;
        },
        componentShow(val) {
            Bus.$emit(this.randomId, val);
        }
    },
    created() {
        API.findCultureSchemeById({
            id: this.id
        }).then(res => {
            this.schemeInfo = res.data;
        });
        this.examineInfo.id = this.id;
    },
    methods: {
        handleAvatarRemove(file, fileList) {
            this.examineFileList = fileList;
            this.examineInfo.evidenceList = _.map(fileList, "name");
        },
        handleUploadSuccess(res, file, fileList) {
            this.examineFileList = fileList;
            this.examineInfo.evidenceList = _.map(fileList, item => {
                return item.response.data[item.name].objectkey;
            });
        },
        submitExamine() {
            // if (
            //     this.examineFileList.length === 0 ||
            //     this.examineInfo.editExplain === ""
            // ) {
            //     this.$message({
            //         message: "材料说明和证明材料不能为空！",
            //         type: "warning"
            //     });
            //     return;
            // }
            // if (
            //     this.examineFileList.length === 0 
            // ) {
            //     this.$message({
            //         message: "签字版培养方案扫描件不能为空！",
            //         type: "warning"
            //     });
            //     return;
            // }
            API.checkCultureScheme(this.examineInfo).then(res => {
                if (res && res.code !== 200) {
                    this.$message({
                        message: res.msg,
                        type: "warning"
                    });
                    return;
                }
                this.examineVisible = false;
                //this.examineInfo.editExplain = "";
                this.examineFileList = [];
                this.$message({
                    message: "提交审批成功！",
                    type: "success"
                });
                this.$router.push({
                    name: "cultureSchemeManage"
                });
                this.show = false;
            });
        },
        closeDialog() {
            this.show = false;
        },
        beforeAvatarUpload(file) {
            let isJPG =false;
            const isLt10M = file.size / 1024 / 1024 < 10;

            if(file.type === 'image/jpeg'){
                isJPG=true;

            }
             if(file.type === 'image/png'){
                isJPG=true;

            }
             if(file.type === 'image/jpg'){
                isJPG=true;

            }

        if (!isJPG) {
          this.$message.error('上传文件只能是 JPG或png 格式!');
        }
        if (!isLt10M) {
          this.$message.error('上传图片大小不能超过 10MB!');
        }
        return isJPG && isLt10M;
      }
    }
};
</script>
